// Hive 实现
import 'package:hive_flutter/hive_flutter.dart';
import 'package:hive_storage/data/local_storage/storage_service.dart';

import '../../models/settings_model.dart'; // 导入模型

class HiveStorageService implements StorageService {
  @override
  Future<void> init() async {
    await Hive.initFlutter();
    // 注册适配器 - 不需要直接引用 .g.dart 文件
    if (!Hive.isAdapterRegistered(0)) {
      Hive.registerAdapter(SettingsModelAdapter());
    }
    await Hive.openBox('settings_box');
  }

  @override
  Future<void> delete(String key) async {
    await Hive.box('setting_box').delete(key);
  }

  @override
  T? get<T>(String key) {
    return Hive.box('settings_box').get(key);
  }

  @override
  Future<void> save<T>(String key, T value) async {
    await Hive.box('settings_box').put(key, value);
  }
}
